import sys
from PyQt5.QtCore import Qt, QUrl
from PyQt5.QtGui import QIcon, QDesktopServices
from PyQt5.QtWidgets import QApplication
from qfluentwidgets import *

from src.kyticket_main import *
from src.default_set import *
from src.add_user import *
from src.ticket_show_all import *
from src.create_ticket import *
from src.upload_ticket import *
from src.export_weekly import *
from src.create_time import *

class Kyticket_Main_Windows(MSFluentWindow):
    
    def __init__(self, parent=None):
        super().__init__(parent)
        self.kyticketMain = kyticket_main(self)
        self.defaultSet = default_set_cls(self)
        self.addUser = add_user_cls(self)
        self.showTitle = ticket_show_cls(self)
        self.creatTitle = creat_title_cls(self)
        self.creatTime = creat_time_cls(self)
        self.uploadTicket = upload_ticket_cls(self)
        self.exportWeekly = export_weekly_cls(self)

        self.initNavigation()
        self.initWindow()

    def initNavigation(self):
        self.addSubInterface(self.kyticketMain, FluentIcon.HOME,'首页', selectedIcon=FluentIcon.HOME_FILL)
        self.addSubInterface(self.defaultSet, FluentIcon.BROOM, '设置默认信息')
        self.addSubInterface(self.addUser, FluentIcon.DEVELOPER_TOOLS, '添加集成商')
        self.addSubInterface(self.showTitle, FluentIcon.VIEW, '查看工单')
        self.addSubInterface(self.creatTitle, FluentIcon.ADD_TO, '添加工单')
        self.addSubInterface(self.creatTime, FluentIcon.ADD_TO, '添加工时')
        self.addSubInterface(self.uploadTicket, FluentIcon.UP, '上传工单')
        self.addSubInterface(self.exportWeekly, FluentIcon.DOWNLOAD, '生成报告')
        self.navigationInterface.addItem('Help',FluentIcon.MUSIC,'战歌',onClick=self.showMessageBox,position=NavigationItemPosition.BOTTOM)
        self.stackedWidget.setStyleSheet('QWidget{background: transparent}')

    def initWindow(self):
        self.resize(1000, 940)
        self.setWindowTitle('麒麟工单补全计划')
        self.setWindowIcon(QIcon('res/ico/ico.png'))
        desktop = QApplication.desktop().availableGeometry()
        w, h = desktop.width(), desktop.height()
        self.move(w//2 - self.width()//2, h//2 - self.height()//2)
    
    def showMessageBox(self):
        w = MessageBox(
            '是时候了',
            '快一起听打工人的战歌',
            self
        )
        w.yesButton.setText('去听')
        w.cancelButton.setText('取消')
        if w.exec():
            QDesktopServices.openUrl(QUrl("https://www.kuwo.cn/play_detail/20274708"))

if __name__ == "__main__":
    QApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
    QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
    QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
    app = QApplication(sys.argv)
    widget = Kyticket_Main_Windows()
    widget.show()
    sys.exit(app.exec())